function [tauVec,boundsMat]=genTauVec(sampleLengths)
% =========================================================================
% Create indicator of which sample does each observation belong to 
% and a position indicator of when do they start and enbd 
%
% Input
% sampleLengths: nx1 vector with the number of observations in each
%                sample
% 
% Output 
% tauVec [Nobs 1] vector assigning each t=1,...,Nobs to a sample 
% boundsMat [n 2] matrix, column 1 is position each which each sample
% starts, column 2 position at which it ends. 
%
% Cannot be used with cummulators as it assumes aborbing breaks (no return) 
% 
% A. Justiniano Dec 22 2011 
% =========================================================================
Nobs=cumsum(sampleLengths); 
Nobs=Nobs(end); 
n=length(sampleLengths); 
tauVec=zeros(Nobs,1); 
boundsMat=zeros(n,2); 
shiftedVec=cumsum([1;sampleLengths(1:end-1)]); 
boundsMat(1,1)=1; 
boundsMat(1,2)=sampleLengths(1)-1; 
for ii=1:n 
    boundsMat(ii,1)=shiftedVec(ii); 
    boundsMat(ii,2)=boundsMat(ii,1)+( sampleLengths(ii) )-1; 
    tauVec(boundsMat(ii,1):boundsMat(ii,2) )=ii; 
end 
